#include <string>
#include "NxFormParam.h"

int NJGIS::SERVICE::NjFormParam::getCount()
{
	return this->_mParams.size();
}

int NJGIS::SERVICE::NjFormParam::getIterByIndex( int index, std::map<std::string, std::string>::iterator &iter )
{
	if(index > this->_mParams.size())
	{
		return -2;
	}
	int localIndex = 0;
	for(iter = this->_mParams.begin(); iter != this->_mParams.end(); ++iter )
	{
		if(localIndex == index)
		{
			return 1;
		}
		localIndex++;
	}
	return -1;
}

const char* NJGIS::SERVICE::NjFormParam::getKey( int index )
{
	std::map<std::string, std::string>::iterator iter;
	if(this->getIterByIndex(index, iter) == 1)
	{
		return iter->first.c_str();
	}
	return NULL;
}

const char* NJGIS::SERVICE::NjFormParam::getValue( int index )
{
	std::map<std::string, std::string>::iterator iter;
	if(this->getIterByIndex(index, iter) == 1)
	{
		return iter->second.c_str();
	}
	return NULL;
}

const char* NJGIS::SERVICE::NjFormParam::getValue( const char* key )
{
	std::map<std::string, std::string>::iterator iter = this->_mParams.find(key);
	if(iter != this->_mParams.end())
	{
		return iter->second.c_str();
	}
	return NULL;
}

int NJGIS::SERVICE::NjFormParam::insertParam( const char* key, const char* value )
{
	this->_mParams.insert(std::pair<std::string, std::string>(key, value));
	return 1;
}


NJGIS::SERVICE::INjFormParam* NJGIS::SERVICE::NjFormHelper::createForm()
{
	return new NJGIS::SERVICE::NjFormParam();
}
